<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>帖子</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

    <link rel="stylesheet" href="/Layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/font-awesome/css/font-awesome.min.css">
</head>

<body>
<div style="margin: 15px;">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>添加文章</legend>
    </fieldset>

    <form class="layui-form layui-form-pane" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入标题"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">标签</label>
            <div class="layui-input-block">
                <input type="text" name="username" lay-verify="required" placeholder="请输入" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">作者</label>
                <div class="layui-input-inline" style="width: 240px;">
                    <input type="text" name="" autocomplete="off" class="layui-input" value="#user('user_name')">
                </div>
                <div class="layui-input-inline layui-hide" style="width: 240px;">
                    <input type="text" name="" autocomplete="off" class="layui-input" value="#user('user_id')">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">日期</label>
                <div class="layui-input-inline" style="width: 240px;">
                    <input placeholder="日期" autocomplete="off" class="layui-input"
                           onclick="layui.laydate({elem: this,min: laydate.now(), max: laydate.now(),format: 'YYYY-MM-DD'})">
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">
                <a id="addHR" class="layui-btn layui-btn-mini"><i class="layui-icon">&#xe654;</i></a>
                <a class="layui-btn layui-btn-mini"><i class="layui-icon">&#xe654;</i></a>
            </label>
            <div class="layui-input-block">
                <textarea class="layui-textarea layui-hide" lay-verify="content" id="editor"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript" src="/Layui/layui.js"></script>
<script>
    layui.use(['jquery', 'form', 'layedit', 'laydate'], function () {
        var form = layui.form(),
            layer = layui.layer,
            layedit = layui.layedit,
            $ = layui.jquery,
            laydate = layui.laydate;

        //创建一个编辑器
        var editIndex = layedit.build('editor');

        $("#addHR").click(function(){

        });


        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value.length < 5) {
                    return '标题至少得5个字符啊';
                }
            },
            content: function (value) {
                layedit.sync(editIndex);
            }
        });


        //监听提交
        form.on('submit(demo1)', function (data) {
            layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            })
            return false;
        });
    });
</script>
</body>

</html>